<?php
declare (strict_types=1);

// +----------------------------------------------------------------------
// | SCApi
// +----------------------------------------------------------------------
// | 版权所有 2021~2022 贾二小 [ http://www.ipsoul.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.ipsoul.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( http://doc.ipsoul.com/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/jiaerxiao/scapi
// | github 代码仓库：https://github.com/jiaerxiao/scapi
// +----------------------------------------------------------------------

namespace app\system\controller;

use app\common\controller\SystemBaseController;
use app\system\facade\TableFacade;
use hg\apidoc\annotation\Group;
use hg\apidoc\annotation\Sort;
use hg\apidoc\annotation\Author;
use hg\apidoc\annotation\Param;
use hg\apidoc\annotation\Method;
use think\App;

/**
 * 表格列管理
 * @Group("System")
 * @Sort(7)
 */
class Table extends SystemBaseController
{
    /**
     * 初始化
     */
    public function initialize()
    {
        $this->logName = "表格列管理";
        parent::initialize();
    }

    /**
     * 列表
     * @Author("贾二小")
     * @since 2021/11/20
     */
    public function list()
    {
        $data = TableFacade::tableList();
        //返回
        self::success($data);
    }

    /**
     * 详情
     * @Author("贾二小")
     * @since 2021/11/23
     */
    public function info()
    {
        $id = intval(input('id'));
        //获取数据
        $data = TableFacade::infoDetails($id);
        //返回
        self::success($data);
    }

    /**
     * 保存
     * @Method("PUT")
     * @Param("id", type="int", desc="唯一ID")
     * @Param("name", type="string", require=true, desc="表格名称")
     * @Param("code", type="string", require=true, desc="标识")
     * @Param("remoteSort", type="boolean", require=true, desc="远程排序")
     * @Param("remoteFilter", type="boolean", require=true, desc="远程过滤")
     * @Author("贾二小")
     * @since 2021/12/6
     */
    public function saving()
    {
        //获取参数
        $paramData = $this->request->put(['id', 'name', 'code', 'remoteFilter', 'remoteSort', 'columns']);
        //参数验证
        $this->validateData($paramData);
        //保存数据
        DicTypeFacade::saving($paramData);
        //返回
        self::success();
    }
}